package com.hongdu.batch.quartz;

import com.hongdu.batch.quartz.config.QuartzService;
import com.hongdu.batch.quartz.job.MyJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.HashMap;

@SpringBootApplication
public class SpringBatchQuartzDemoApplication implements CommandLineRunner {

	@Autowired
	private QuartzService quartzService;

	public static void main(String[] args) {
		SpringApplication.run(SpringBatchQuartzDemoApplication.class, args);
	}

	@Override
	public void run(String... strings) throws Exception {
		HashMap<String,Object> map = new HashMap<>();
		map.put("name",1);
		quartzService.deleteJob("job", "test");
		quartzService.addJob(MyJob.class, "job", "test", "0 * * * * ?", map);

		map.put("name",2);
		quartzService.deleteJob("job2", "test");
		quartzService.addJob(MyJob.class, "job2", "test", "10 * * * * ?", map);

		map.put("name",3);
		quartzService.deleteJob("job3", "test2");
		quartzService.addJob(MyJob.class, "job3", "test2", "15 * * * * ?", map);
	}
}
